package com.atguigu.exam.exceptionhandlers;

import com.atguigu.exam.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        e.printStackTrace();
        // 记录日志异常
        log.error("服务器发生运行时异常！异常信息为：{}",e.getMessage());
        // 返回自定义异常结果
        return Result.error(e.getMessage());
    }
}


